import { request } from "./request";

//获得商品列表
export function getCategoryList(queryInfo) {
  return request({
    method: "get",
    url: "/category",
    params: queryInfo //参数为类型为object,不用加花括号进行参数指定
  });
}
//获得商品列表
export function getParentIds(id) {
  return request({
    method: "get",
    url: "/category/parentIds",
    params: {
      id: id
    }
  });
}

//查询分类名称及id
export function getCategoryKeyName(type) {
  return request({
    method: "get",
    url: `/category/${type}`
  });
}
//添加商品分类
export function addCategory(cateInfo) {
  return request({
    method: "post",
    url: "/category",
    data: cateInfo //参数为类型为对象类型,不用加花括号进行参数指定
  });
}
//修改商品分类
export function editCategory(cateInfo) {
  return request({
    method: "put",
    url: "/category",
    data: cateInfo //参数为类型为对象类型,不用加花括号进行参数指定
  });
}
//删除分类
export function deleteCategory(id) {
  return request({
    method: "delete",
    url: `/category/${id}`
  });
}

//根据商品分类查询参数列表
export function getCategoryAttributes(cateId, type) {
  return request({
    method: "get",
    url: `/category/${cateId}/params`,
    params: {
      type: type
    }
  });
}
//根据分类id和分类参数id查询动态参数或静态属性
export function getCategoryParam(cateId, id) {
  return request({
    method: "get",
    url: `/category/${cateId}/params/${id}`
  });
}

//添加动态参数或静态属性
export function addCategoryParam(cateId, categoryParam) {
  return request({
    method: "post",
    url: `/category/${cateId}/params`,
    data: categoryParam //参数为类型为object,不用加花括号进行参数指定
  });
}

//修改动态参数或静态属性
export function editCategoryParam(editParam) {
  return request({
    method: "put",
    url: `/category/${editParam.cateId}/params`,
    data: editParam
  });
}

//根据id删除商品分类的动态参数或静态属性
export function deleteCateParam(cateId, id) {
  return request({
    method: "delete",
    url: `/category/${cateId}/params/${id}`
  });
}
